package com.robam.cloud.authcenter.controller;

import com.robam.cloud.authcenter.service.AuthService;
import com.robam.cloud.common.bean.restful.entity.RespMsg;
import com.robam.cloud.log.annotation.OperationLogRecord;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Api("三方登录授权控制类")
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Autowired
    AuthService authService;
    @Autowired
    HttpServletRequest httpServletRequest;


    /**
     * @param platformUuid 三方平台在表中的uuid
     * @param code         微信支付宝的授权code
     * @param ticket       浙里办的授权ticket
     * @param dealKey      鹿径科技平台的dealkey
     * @return
     */
    @ApiOperation(
            value = "三方认证返回token",
            notes = "三方认证携带token")
    @RequestMapping(
            value = "/getToken",
            method = RequestMethod.GET)
    @OperationLogRecord(
            describe = "三方认证携带token回调地址",
            modularCode = "auth-getAuthInfo",
            operationLevel = OperationLogRecord.OperationLevel.OTHER)
    public RespMsg<String> getToken(@RequestParam(value = "platformUuid") String platformUuid,
                                    @RequestParam(value = "code", required = false) String code,
                                    @RequestParam(value = "ticket", required = false) String ticket,
                                    @RequestParam(value = "dealKey", required = false) String dealKey) {
        return RespMsg.success(authService.getToken(platformUuid, code, ticket, dealKey, httpServletRequest));
    }
}
